<?php  include("authenticate.php");?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CP2010 MySql Exercise</title>
<link rel="stylesheet" type="text/css" href="style.css"/>

<?php 	
	// if user clicked submit button
	if (isset($_REQUEST['email']))
	{
		// construct a delete query
		$delete_query = "DELETE FROM colleague WHERE email= '" . $_REQUEST['email'] . "'";
		
		$myDB = new db();
 		$result = $myDB->sendSQLStatement($delete_query);
		
		// check result
		if ($result == TRUE)
			echo "<p>Record is deleted from database.</p>";
		else 
			echo "<p <p style='color:red'>Fail to delete selected record from database.</p>";			
	}
?>
</head>

<body class="twoColElsLtHdr">

<div id="container">
  <div id="header">
  	<table width="100%" border="0px">
    <tr><td rowspan="2"><h1>Address Book</h1></td>
    <td style="color:#039; font-weight: bold; text-align:right;"><?php	echo 'User: ' . $_SESSION['userEmail']?></td></tr>
    <tr><td style="color:#039; font-weight: bold; text-align:right;"><a href="signBook.php">Open Sign Book</a></td><tr>
    </table>
  <!-- end #header --></div>
  <div id="sidebar1">
     <h3><a href="index.php">Home</a></h3>
    <h3><a href="addAddress.php">Add</a></h3>
    <h3><a href="modifyAddress.php">Modify</a></h3>
  <!-- end #sidebar1 --></div>
  <div id="mainContent">
  	<p>
    <!-- upon the page launch, retrieve all records from table colleague and display -->
    <h2>Select a record to delete </h2>     
	<form action="deleteAddress.php" method="get">  
        <table border="1" cellpadding="10px" cellspacing="0">
        <tr>
        <th></th>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Telephone</th>
        <th>Email Address</th>                
        </tr>
        <?php
			$myDB = new db();
 			$result = $myDB->sendSQLStatement("SELECT * FROM colleague");
            //loop through all table rows
            while ($row = mysql_fetch_array($result)) {
                echo "<tr>";
                echo "<td><input name='email' type='radio' value='" . $row['email'] . "' /></td>";
                echo "<td>" . $row['firstname'] . "</td>";
                echo "<td>" . $row['lastname'] . "</td>";
                echo "<td>" . $row['telephone'] . "</td>";
                echo "<td>" . $row['email'] . "</td>";			
                echo "</tr>";										
            }
            // free result memory 
            mysql_free_result($result);
									
        ?>
        </table>

    	<p align='center'><input type="submit" name="Submit" value="Submit" /> </p>
    </form>
	<!-- end #mainContent --></div>
	<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
   <div id="footer">
    <p>CP2010 MySql Exercise</p>
  <!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>